home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / OS / ZCursor.h < prev    next >
Text File  |  1997-05-30  |  5KB  |  193 lines

  1. /*
  2.  *  File:       ZCursor.h
  3.  *  Summary:    Mouse cursor classes.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *    Classes:    TCursor                - Encapsulates color and b/w cursors.
  7.  *                UCursorUtils        - Cursor utility functions.
  8.  *                TForceBusyCursor    - Stack based class to display a busy cursor.
  9.  *                THideCursor            - Stack based class to hide the cursor.
  10.  *
  11.  *  Copyright ゥ 1996 Jesse Jones. 
  12.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  13.  *
  14.  *  Change History (most recent first):    
  15.  *
  16.  *         <->     2/24/96    JDJ        Created.
  17.  */
  18.  
  19. #pragma once
  20.  
  21. #include <QuickDraw.h>
  22.  
  23. #include <ZGeometry.h>
  24. #include <ZTypes.h>
  25.  
  26.  
  27. //-----------------------------------
  28. //    Forward References
  29. //
  30. class ZCursorSpinner;
  31.  
  32. struct CursorDevice;
  33.  
  34.  
  35. // ===================================================================================
  36. //    class TCursor
  37. // ===================================================================================
  38. class TCursor {
  39.  
  40.     friend class UCursorUtils;
  41.  
  42. public:
  43.                         ~TCursor();
  44.     
  45.     explicit             TCursor(ResID id);
  46.     
  47.                         TCursor(const TCursor& rhs);
  48.             
  49.                         TCursor& operator=(const TCursor& rhs);
  50.             
  51.             bool         operator==(const TCursor& rhs) const        {return mID == rhs.mID;}
  52.             
  53.             bool         operator!=(const TCursor& rhs) const        {return mID != rhs.mID;}
  54.  
  55.             bool         operator<(const TCursor& rhs) const            {return mID < rhs.mID;}
  56.  
  57. private:
  58.     CCrsrHandle    mColorCursor;
  59.     Cursor*        mBwCursor;
  60.     ResID        mID;
  61. };
  62.  
  63.  
  64. // ===================================================================================
  65. //    Standard Cursors
  66. // ===================================================================================
  67. extern const TCursor kArrowCursor;            // Standard cursors
  68. extern const TCursor kCrossHairCursor;
  69. extern const TCursor kIBeamCursor;
  70. extern const TCursor kPlusCursor;
  71. extern const TCursor kWatchCursor;
  72.  
  73. extern const TCursor kOpenHandCursor;        // A few other common cursors
  74. extern const TCursor kClosedHandCursor;    
  75. extern const TCursor kEyeDropperCursor;
  76. extern const TCursor kBrushCursor;
  77. extern const TCursor kPencilCursor;
  78.  
  79. extern const TCursor kSpinningWatchCursor;    // Animated cursors
  80. extern const TCursor kBeachBallCursor;
  81. extern const TCursor kEmptyArrowCursor;
  82.  
  83.  
  84. // ===================================================================================
  85. //    class UCursorUtils
  86. // ===================================================================================
  87. class UCursorUtils {
  88.  
  89.     friend class TForceBusyCursor;
  90.     
  91. //-----------------------------------
  92. //    Initialization
  93. //
  94. public:
  95.     static    void         Init();
  96.                         // Makes the cursor visible and sets it to kArrowCursor. Note
  97.                         // that this can be called more than once.
  98.  
  99. //-----------------------------------
  100. //    Cursor Operations
  101. //
  102. public:
  103.     static     void         SetCursor(const TCursor& cursor);
  104.                         // Changes the cursor and stops the busy cursor animation
  105.                         // (if cursor != msBusyCursor).
  106.     
  107.     static     void         ObscureCursor()                            {::ObscureCursor();}
  108.                         // Hides the cursor until the mouse moves.
  109.         
  110. //-----------------------------------
  111. //    Busy Cursor
  112. //
  113. public:
  114.     static     void         StillBusy();
  115.                         // Call this for long tasks to avoid timing out. Note that 
  116.                         // this does nothing if the busy cursor isn't already up.
  117.  
  118.     static     void         ForceBusy();
  119.                         // Puts up a busy cursor that animates until it times out or
  120.                         // SetCursor is called with a different cursor.
  121.     
  122.     static     void         ForceBusy(const TCursor& cursor);
  123.     
  124.     static     void         SetTimeout(MilliSecond duration);
  125.                         // Defaults to 5 seconds.
  126.         
  127.     static     MilliSecond GetTimeout();
  128.     
  129.     static     void         InstallCustomBusyCursor(const TCursor& newCursor);
  130.                         // Defaults to kSpinningWatchCursor.
  131.  
  132. //-----------------------------------
  133. //    Cursor Moving
  134. //
  135. public:
  136.     static    TPoint        GetPosition();
  137.                         // Returns the mouse position in global coordinates.
  138.  
  139.     static     bool         CanMove();
  140.                         // Returns false if there's a cursor device that cannot be moved 
  141.                         // (like a TouchWindow).
  142.     
  143.     static    void         MoveTo(short x, short y);
  144.                         // Use global coordinates!
  145.                         
  146.     static    void         MoveBy(short dx, short dy);
  147.                         // Move the mouse a relative distance. 
  148.  
  149. //-----------------------------------
  150. //    Member data
  151. //
  152. private:
  153.     static TCursor            msBusyCursor;
  154.     static TCursor            msCurrentCursor;
  155.     static ZCursorSpinner*     msCursorSpinner;
  156.     
  157.     static CursorDevice*    msCursorDevice;
  158.     static bool                msCanMoveMouse;
  159. };
  160.  
  161.  
  162. // ===================================================================================
  163. //    class TForceBusyCursor
  164. // ===================================================================================
  165. class TForceBusyCursor {
  166.  
  167. public:
  168.                         ~TForceBusyCursor();
  169.  
  170.                         TForceBusyCursor();
  171.  
  172.                         TForceBusyCursor(const TCursor& cursor);
  173.  
  174.             void         StillBusy()                                    {UCursorUtils::StillBusy();}
  175.  
  176. private:
  177.     TCursor        mOldCursor;
  178.     bool        mWasBusy;
  179. };
  180.  
  181.  
  182. // ===================================================================================
  183. //    class THideCursor
  184. // ===================================================================================
  185. class THideCursor {
  186.  
  187. public:
  188.                         ~THideCursor()                                {::ShowCursor();} 
  189.  
  190.                          THideCursor()                                {::HideCursor();} 
  191. };
  192.  
  193.